///*
//package com.jcxh.sg_exam.aop;
//
//import org.aspectj.lang.ProceedingJoinPoint;
//import org.aspectj.lang.annotation.Around;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.reflect.MethodSignature;
//import org.springframework.core.annotation.AnnotationUtils;
//import io.swagger.annotations.ApiOperation;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Component;
//import java.io.FileWriter;
//import java.io.IOException;
//import java.time.LocalDateTime;
//import java.time.format.DateTimeFormatter;
//
//@Aspect
//@Component
//@Slf4j
//public class TimeAspect {
//
//    private static final String LOG_FILE_PATH = "src/main/resources/log.txt"; // 指定日志文件路径
//
//    @Around("execution(* com.jcxh.sg_exam.controller.*.*(..))")
//    public Object recordTime(ProceedingJoinPoint joinPoint) throws Throwable {
//        long beginTime = System.currentTimeMillis();
//
//        // 获取方法签名
//        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
//        String methodName = signature.getMethod().getName();
//
//        // 获取方法的 @ApiOperation 注释
//        ApiOperation apiOperation = AnnotationUtils.findAnnotation(signature.getMethod(), ApiOperation.class);
//        String operationDescription = apiOperation != null ? apiOperation.value() : "未知接口";
//
//        // 执行原始方法
//        Object result = joinPoint.proceed();
//
//        long endTime = System.currentTimeMillis();
//
//        // 获取当前时间并格式化
//        LocalDateTime now = LocalDateTime.now();
//        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
//        String formattedDateTime = now.format(formatter);
//
//        // 构建完整的日志信息字符串
//        String logMessage = String.format("%s %s 执行耗时: %d毫秒", formattedDateTime, operationDescription, endTime - beginTime);
//
//        // 记录到控制台
//        log.info(logMessage);
//
//        // 写入文件
//        writeLogToFile(logMessage);
//
//        return result;
//    }
//
//    private void writeLogToFile(String logMessage) {
//        try (FileWriter writer = new FileWriter(LOG_FILE_PATH, true)) {
//            writer.write(logMessage + System.lineSeparator());
//        } catch (IOException e) {
//            log.error("写入日志文件失败", e);
//        }
//    }
//}*/
